using System;
using System.Collections.Specialized;
using AppToolKit.Core.Context.Spring;
using Common.Logging;

using Spring.Context;
using Spring.Context.Support;
using Spring.Data.Config;
using Spring.Objects.Factory.Xml;
using Spring.Transaction.Config;

namespace CenterDateAchieve.Test.Init
{
    public abstract class ContextFixureBase
    {
        private IApplicationContext app_ = null;
        private ContextAware context_ = null;

        public ContextFixureBase()
        {
            //ConfigurationReader reader=new ConfigurationReader();
            //reader.GetSection()
           
            NameValueCollection properties = new NameValueCollection();
            properties["showDateTime"] = "true";

            // set Adapter
           LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(properties);

           
        }

        protected void Init(string[] appPath)
        {
            NamespaceParserRegistry.RegisterParser(typeof(TxNamespaceParser));
            NamespaceParserRegistry.RegisterParser(typeof(DatabaseNamespaceParser));
          


            app_ = new XmlApplicationContext(appPath);
            
            Context=(ContextAware)app_.GetObject("ContextAwareSlot");
        }

        public ContextAware Context
        {
            get { return context_; }
            set { context_ = value; }
        }

        public void Dispose()
        {
            app_.Dispose();
        }

        public object LoadObject(string name)
        {
            return Context.GetObject(name);
        }

        public object LoadObject(Type type)
        {
            return Context.GetAutoWiringObject(type);
        }

        public object LoadObject<T>()
        {
            return Context.GetAutoWiringObject(typeof(T));
        }

      
    }
}